$(document).ready(function () {
    GetRequestData(GetRequest())
});

function GetRequestData(list){
    console.log(list)
    if(JSON.stringify(list) != "{}"){
        $("#searchInput").val(list['id']);
        getData(list['id'],list['date'])
    }
}

function getData(id,date){
    $.ajax({
        url: global.apiUrl + '/admin_eat_order',
        type: 'GET',
        dataType: 'json',
        data: {
            start_time: date,
            end_time: date,
            userid: id
        },
        header: {
            'content-type': 'application/json' //默认值
        },
        success: function(res){
            // console.log(res)
            var list = res.content[0]
            var title = '';
            title += `<div class="titleItem">
                        <text>${list.user_content.nickname}</text>
                        <text>${list.user_content.sex}</text>
                        <text>${list.user_content.height}cm</text>
                        <text>ID: ${list.user_id}</text>
                    </div>
                    <text style="margin-right: 20px">时间：${list.date}</text>`
            $('#titleAre').html(title)
            var html = ''            
            for(var i in res.content){
                html += `
                        <div class="foodItemAre">
                            <text style="font-size:16px">${getFoodType(res.content[i].type)}</text>
                            <text style="margin:5px 0">${res.content[i].remark?res.content[i].remark:'-'}</text>
                            <div class="lightBoxGallery">
                                ${getImgAre(res.content[i].img,getFoodType(res.content[i].type))}
                            </div>
                        </div>`
            }
            $('#foodDetails').html(html)
        }
    })
}

function getImgAre(list,type){
    var a = ''
    if(list != ''){
        var arr = list.split(',')
        for(var i in arr){
            a += `<a href="${global.apiUrl + arr[i]}" title="${type}" data-gallery=""><img src="${global.apiUrl + arr[i]}"></a>`
        }
    }
    return a
}